local kanpo = fk.CreateSkill({
  name = "mini_ex__kanpo",
})

Fk:loadTranslationTable{
  ["mini_ex__kanpo"] = "看破",
  [":mini_ex__kanpo"] = "每轮开始时，你可以记录一个锦囊牌的牌名（每种牌名限一次），"..
  "本轮当其他角色使用与你记录牌名相同的牌时，你令此牌无效并摸一张牌。",

  ["#mini_ex__kanpo-choice"] = "看破：记录一种锦囊牌，其他角色使用此牌时，你令其无效并摸一张牌",
  ["@[private]$mini_ex__kanpo-round"] = "看破",

  ["$mini_ex__kanpo1"] = "",
  ["$mini_ex__kanpo2"] = "",
}

local U = require "packages/utility/utility"

kanpo:addEffect(fk.RoundStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(kanpo.name) and #player:getTableMark(kanpo.name) > 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local name = U.askForChooseCardNames(room, player, player:getTableMark(kanpo.name),
      1, 1, kanpo.name, "#mini_ex__kanpo-choice", Fk:getAllCardNames("td", true), true)
    if #name > 0 then
      event:setCostData(self, {choice = name[1]})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = event:getCostData(self).choice
    room:removeTableMark(player, kanpo.name, choice)
    U.setPrivateMark(player, "$mini_ex__kanpo-round", {choice})
  end,
})

kanpo:addEffect(fk.CardUsing, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(kanpo.name) and target ~= player and
      table.contains(U.getPrivateMark(player, "$mini_ex__kanpo-round"), data.card.trueName)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.toCard = nil
    data:removeAllTargets()
    player:drawCards(1, kanpo.name)
  end,
})

kanpo:addAcquireEffect(function (self, player, is_start)
  player.room:setPlayerMark(player, kanpo.name, Fk:getAllCardNames("td", true))
end)

return kanpo
